package com.example.springbook.book.controller;

import com.example.springbook.book.service.UserService;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/login")
    public Boolean login(String name, String password, HttpSession session) {
        log.info("接收到参数:" + name);
        //1.校验参数格式
        //2.从数据库校验账号密码
        //3.如果正确,存储session,返回true
        Boolean result = userService.checkUserAndPassword(name, password, session);
        log.info("用户登录, name:{}, 结果: {}", name, result);
        return result;
    }
}
